<template>
	<view class="enterprise">

	<u-navbar 
		title="创建企业"
		:border-bottom="false"  
	></u-navbar>

	<view class="information__box">
		<view @click="chooseLogo" class="information__box__basicInfo">
			<v-require-text class="information__box__basicInfo__type">
				企业logo
			</v-require-text>
			<!-- <u-avatar :src="enterpriseData.logo" size="100" style="margin-right: 10px;"></u-avatar>
			 -->
			 <view v-if="logo!=''" class="information__box__basicInfo__image">
				<u-image :src="logo.path"  width="100%" height="100%" ></u-image>
			 </view>
			 <view v-else class="information__box__basicInfo__text">上传图片</view>
			 <u-icon class="information__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			 <!-- <u-icon  class="information__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon> -->
		</view>
		<view  class="information__box__basicInfo">
			<v-require-text class="information__box__basicInfo__type">
				企业代码
			</v-require-text>
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="code"
					input-align="right"
					placeholder="输入企业代码"
					:border-bottom="false"
				>
				</u-field>
			</view >
		</view>
		<view @click="nameModal=true" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				企业名称
			</view>
			
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="name"
					input-align="right"
					placeholder="输入企业名称"
					:border-bottom="false"
				>
				</u-field>
			</view >
				
		</view>
		<view  class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				企业简介
			</view>
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="briefIntroduction"
					input-align="right"
					placeholder="输入企业简介"
					:border-bottom="false"
				>
				</u-field>
			</view >
		</view>
		<view @click="phontModal=true" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				企业联系方式
			</view>
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="phone"
					input-align="right"
					placeholder="输入企业联系方式"
					:border-bottom="false"
				>
				</u-field>
			</view >
		</view>
		<view @click="addressModal=true" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				地址
			</view>
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="address"
					input-align="right"
					placeholder="输入企业地址"
					:border-bottom="false"
				>
				</u-field>
			</view >
		</view>
		
		<view @click="chooselicense" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				营业执照
			</view>
			 <view v-if="businessLinence!=''" class="information__box__basicInfo__image">
				<u-image :src="businessLinence.path"  width="100%" height="100%" ></u-image>
			 </view>
			 <view v-else class="information__box__basicInfo__text">上传图片</view>
			 <u-icon class="information__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
		</view>
		
		<view @click="legalModal=true" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				公司法人姓名
			</view>
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="legalPersonName"
					input-align="right"
					placeholder="输入法人姓名"
					:border-bottom="false"
				>
				</u-field>
			</view >
		</view>
		
		<view  class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				公司法人身份证号
			</view>
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="identityNumber"
					input-align="right"
					placeholder="输入法人身份证号"
					:border-bottom="false"
				>
				</u-field>
			</view >
		</view>
		
		<view @click="chooseCertificate" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				法人身份证
			</view>
			 <view v-if="legalPersonCertificate!=''" class="information__box__basicInfo__image">
				<u-image :src="legalPersonCertificate.path"  width="100%" height="100%" ></u-image>
			 </view>
			 <view v-else class="information__box__basicInfo__text">上传图片</view>
			 <u-icon class="information__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
		</view>
		
		<view @click="establishTimePicker=true" class="information__box__basicInfo">
			<v-require-text class="information__box__basicInfo__type">
				公司入驻日期
			</v-require-text>
		
			<view v-if="establishmentDate!=''" class="information__box__basicInfo__value">
				{{establishmentDate}}
			</view>
			<view v-else  class="information__box__basicInfo__text">请选择</view>
			<u-icon class="information__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			<u-picker mode="time"
				v-model="establishTimePicker" 
				:params="timePickerParams"
				@confirm="establishTimeConfirm">
			</u-picker>	
		</view>
		<view @click="parkSelect=true" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				所在园区
			</view>
			<view v-if="parkId!=''" class="information__box__basicInfo__value">
				{{parkName}}
			</view>
			<view v-else class="information__box__basicInfo__text">
				请选择
			</view>
			
			<u-icon class="information__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			<u-select 	v-model="parkSelect"
						:list="parkList" 
						@confirm="parkConfirm"
						value-name="id"
						label-name="parkName"></u-select>
		</view>
		
		<view @click="room_idModal=true" class="information__box__basicInfo">
			<view class="information__box__basicInfo__type">
				房间ID
			</view>
			<view class="information__box__basicInfo__input">
				<u-field
					v-model="rootId"
					input-align="right"
					placeholder="输入房间号"
					:border-bottom="false"
				>
				</u-field>
			</view>
		</view>
		
		<view @click="entryTimePicker=true" class="information__box__basicInfo">
			<v-require-text class="information__box__basicInfo__type">
				公司入驻日期
			</v-require-text>
		
			<view v-if="entryTime!=''" class="information__box__basicInfo__value">
				{{entryTime}}
			</view>
			<view v-else class="information__box__basicInfo__text">请选择</view>
			<u-icon class="information__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			<u-picker mode="time"
				v-model="entryTimePicker" 
				:params="timePickerParams"
				@confirm="entryTimeConfirm">
			</u-picker>	
		</view>
	</view>
	<view class="bottom-box">
		<view class="bottom-box__cancel" @click="cancelModel=true">取消</view>
		<view class="bottom-box__submit" @click="clickSubmit">提交</view>
	</view>
	<u-modal v-model="cancelModel"
		:show-title="false"
		content="确认取消"
		:show-cancel-button="true"
		confirm-color="#177fff"
		@confirm="goback">
	</u-modal>
	<u-modal v-model="submitModel" 
		:show-title="false"
		content="确认提交"
		:show-cancel-button="true"
		confirm-color="#177fff"
		@confirm="submit">
	</u-modal>
	</view>
</template>

<script>
	import enterpriseData from "./enterpriseData.js"
	
	import requireText from '../../../../component/requireText.vue'
	import axios from "axios"
	export default {
		components:{
			'v-require-text':requireText
		},
		data() {
			return {
				code:"",
				name:"",
				logo:"",
				briefIntroduction:"",
				picture:[],
				phone:"",
				address:"",
				legalPersonName:"",
				establishmentDate:"",
				businessLinence:"",
				businessScope:"",
				legalPersonCertificate:"",
				identity:"",
				parkId:"",
				parkName:"",
				rootId:"",
				entryTime:""	,
				entryTimePicker:false,
				establishTimePicker:false,
				timePickerParams:{
					year: true,
					month: true,
					day: true,
				},
				parkSelect:false,
				parkList:[],

				cancelModel:false,
				submitModel:false

			}
		},
		mounted(){
			this.getParkList()
		},
		methods: {
			getParkList(){
				this.$Axios({
					method:"get",
					url:this.$store.state.baseURL+"/park/all",
				}).then((response)=>{
					let responseData=response.data
					console.log(responseData)
					this.parkList=response.data.msg;
				});
			},
			chooseLogo(){
				console.log("this.logo",this.logo)
				let _this=this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera','album'], //从相册选择
					success: function (res) {
						//上传图片
						_this.logo=res.tempFiles[0]
					}
				})
				console.log("this.logo",this.logo)
			},

			chooselicense(){
				let _this=this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera','album'], //从相册选择
					success: function (res) {
						//上传图片
						_this.businessLinence=res.tempFiles[0]
						
					}
				})
			},

			
			chooseCertificate(){
				let _this=this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera','album'], //从相册选择
					success: function (res) {
						//上传图片
						_this.legalPersonCertificate=res.tempFiles[0]
					}
				})
			},

			getFormatDate(year,month,day){
				// month=month>=10?month:'0'+month;
				// day=day>=10?day:'0'+day;
				return year+"-"+month+"-"+day+" 00:00:00";
			},
			getRequestDateFormat(dateString){
				let date=dateString.split("-");
				return data[0]+date[1]+data[2]+" 00:00:00";
			},
			entryTimeConfirm(date){
				this.entryTime=this.getFormatDate(date.year,date.month,date.day)		
			},
			establishTimeConfirm(date){
				this.establishmentDate=this.getFormatDate(date.year,date.month,date.day)
			},
			parkConfirm(park){
				console.log(park);
				this.parkId=park[0].value;
				this.parkName=park[0].label
			},
			clickSubmit(){
				
				if(this.name==''){
					uni.showToast({
						title:"请输入企业名称",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.code==''){
					uni.showToast({
						title:"请输入企业代码",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.phone==''){
					uni.showToast({
						title:"请输入企业联系方式",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.logo==''){
					uni.showToast({
						title:"请选择企业logo",
						icon:"none",
						duration:2000
					})
					return
				}

				if(this.address==''){
					uni.showToast({
						title:"请填写企业地址",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.code==''){
					uni.showToast({
						title:"请填写企业法人",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.establishmentDate==''){
					uni.showToast({
						title:"请选择企业创建时间",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.businessLinence==''){
					uni.showToast({
						title:"请上传企业营业执照",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.legalPersonCertificate==''){
					uni.showToast({
						title:"请上传法人身份证",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.identityNumber==''){
					uni.showToast({
						title:"请填写法人身份证号",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.parkId==''){
					uni.showToast({
						title:"请选择园区",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.rootId==''){
					uni.showToast({
						title:"请填写房间号",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.entryTime==''){
					uni.showToast({
						title:"请选择入驻时间",
						icon:"none",
						duration:2000
					})
					return
				}
				this.submitModel=true	
			},
			submit(){
				uni.showLoading({
					title:"提交中...",
				})
				let addData=new FormData()
				addData.append("code",this.code)
				console.log("name","this.name")
				addData.append("name",this.name)
				addData.append("logo",this.logo)
				addData.append("briefIntroduction",this.briefIntroduction)
				addData.append("phone",this.phone)
				addData.append("type","1")
				addData.append("address",this.address)
				addData.append("legalPersonName",this.legalPersonName)
				addData.append("establishmentDate",this.establishmentDate)
				addData.append("businessLicense",this.businessLinence)
				addData.append("businessScope",this.businessScope)
				addData.append("legalPersonCertificate",this.legalPersonCertificate)
				addData.append("identityNumber",this.identityNumber)
				addData.append("parkId",this.parkId)
				addData.append("entryTime",this.entryTime)
				// addData.append("entryTime",this.enteryTime)
				axios({
					url:this.$store.state.baseURL+"/enterprise/add",
					method:"post",
					headers:{
						// "Content-Type":"multipart/form-data; boundary=----WebKitFormBoundary5NqxviCXpyAjOEV6boundary",
						"Authorization":uni.getStorageSync("token")
					},
					data:addData
				}).then(response=>{
					if(response.data.satus=="Success"){
						uni.showToast({
							title:"创建成功",
							icon:"none",
							duration:2000
						})
					}else{
						uni.showToast({
							title:response.data.msg,
							icon:"none",
							duration:2000
						})
					}
				}).catch((e)=>{
					uni.showToast({
						title:e,
						icon:"none",
						duration:2000,
					})
				})
				// 提交请求
				// uni.showToast({
				// 	title:"提交成功",
				// 	icon:"none",
				// 	duration:2000,
				// 	success() {
				// 		setTimeout(function(){
				// 			uni.navigateTo({
				// 				url:"/pages/core/mine/enterprise/myEnterprise"
				// 			});
				// 		},500)
				// 	}
				// })
			
			}
		}
	}
</script>

<style lang="less">
.enterprise{
	background-color: @uni-bg-color-grey;
	padding-bottom: calc(10vh);
}
.information{

	&__box{
		margin-top: @uni-spacing-row-sm;
		background-color: #fff;
		&__basicInfo{
			margin: 30rpx 30rpx;
			display: flex;
			justify-content: flex-end;
			align-items: center;
			padding: auto 5rpx ;
			border-bottom: 0.1px solid #dde3f1;
			height: @uni-list-heigh-base;
			&__modal{
				display: flex;
				flex-direction: column;
				&__button{
					margin:15rpx auto;
					text-align: center;
					padding: 10rpx 90rpx;
				}
				&__button :hover{
					background-color: #f4f4f4;
						
				}
				&__item{
					margin:0px auto 10px 30px;
				}
			}
			&__type{
				margin-right: auto;
			}
			&__image{
				width: @uni-img-size-lg;
				height: @uni-img-size-lg;
				// border-radius: @uni-border-radius-circle;
				// border: 1px solid @color-blue;
			}
			&__text{
				color: @font-color-grey;

			}
			&__value{
				color: #000000;
			}
			&__arrow{
				margin-right: @uni-spacing-row-lg;
			}
			&__input{
				flex: 1;
			}
		}
	}
}
.bottom-box{
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	position: fixed;
	padding: @uni-spacing-row-lg @uni-spacing-col-lg;
	bottom: 0;
	width: calc(100vw);
	background-color: #fff;
	
	&__cancel{
		margin-right: @uni-spacing-col-lg;
		padding-top: @uni-spacing-row-base;
		padding-bottom: @uni-spacing-row-base;
		text-align: center;
		flex: 0.5;
		border-radius: @uni-border-radius-base;
		border: 1px solid @font-color-blue;
		font-size: @uni-font-size-lg;
		color: @font-color-blue;
	}
	&__submit{
		padding-top: @uni-spacing-row-base;
		padding-bottom: @uni-spacing-row-base;
		text-align: center;
		flex: 1;
		border-radius: @uni-border-radius-base;
		border: 1px solid @font-color-blue;
		background-color: @uni-bg-color-blue;
		font-size: @uni-font-size-lg;
		color: #fff;
	}
}
</style>
